package com.ruigi.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@Component
@Slf4j
public class Mymetahandler implements MetaObjectHandler {

    /**
     * 自定义元数据处理器
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser",Basecontext.getid());
        metaObject.setValue("createUser",Basecontext.getid());




    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        HttpSession session = request.getSession();
//        Long employee= (Long) session.getAttribute("employee");
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser",Basecontext.getid());



        long id = Thread.currentThread().getId();
        log.info("id+{}",id);

    }
}
